package com.example.lib_common.glide;

import android.content.Context;

import androidx.annotation.NonNull;

import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.engine.Engine;
import com.bumptech.glide.load.engine.cache.DiskLruCacheFactory;
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory;
import com.bumptech.glide.load.engine.cache.LruResourceCache;
import com.bumptech.glide.load.engine.cache.MemorySizeCalculator;
import com.bumptech.glide.module.AppGlideModule;

/**
 * @author yaotianxue
 * @description
 * @date 2025/3/11
 */
@com.bumptech.glide.annotation.GlideModule
public class GlideModule extends AppGlideModule {
    @Override
    public void applyOptions(@NonNull Context context, @NonNull GlideBuilder builder) {

        // 设置内存缓存大小
        int memoryCacheSizeBytes = 1024 * 1024 * 100; // 100 MB
        builder.setMemoryCache(new LruResourceCache(memoryCacheSizeBytes));
        // 设置磁盘缓存目录和大小
        String diskCachePath = context.getExternalCacheDir().getPath() + "/glide_cache";
        int diskCacheSizeBytes = 1024 * 1024 * 500; // 500 MB
        builder.setDiskCache(new DiskLruCacheFactory(diskCachePath, diskCacheSizeBytes));


    }
}
